﻿package mortal.game.scene3D.layer3D.utils
{
    import baseEngine.basic.*;
    import baseEngine.system.*;
    import flash.display3D.*;
    import flash.geom.*;
    import frEngine.core.*;
    import frEngine.manager.*;
    import frEngine.pools.*;
    import frEngine.postProcess.*;
    import frEngine.primitives.*;
    import frEngine.render.layer.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.fragmentFilters.extra.*;

    public class PixsMask extends FrPlane
    {
        private var _mapX:int = 0;
        private var _mapY:int = 0;
        private var _isOverEffect:Boolean = false;
        private var pixsFilter:PixsMaskFilter;

        public function PixsMask(param1:String = "quad")
        {
            this.pixsFilter = new PixsMaskFilter(null);
            super(param1);
            return;
        }// end function

        override public function reinit(param1:RenderList, param2:Number, param3:Number, param4, param5:Boolean, param6:Vector3D, param7:String = "+xy") : void
        {
            this.pixsFilter.texture = Resource3dManager.instance.getTexture3d(param4, 0);
            super.reinit(param1, param2, param3, this.pixsFilter, false, null, param7);
            return;
        }// end function

        public function updatePos() : void
        {
            var _loc_1:* = Scene3DUtil.change2Dto3DX(this._mapX);
            var _loc_2:* = Scene3DUtil.change2Dto3DY(this._mapY);
            setPosition(_loc_1, 0, _loc_2);
            return;
        }// end function

        override public function draw(param1:Boolean = true, param2:ShaderBase = null) : void
        {
            if (this._isOverEffect && !PostProcess.instance.isRenderingShadow || !this._isOverEffect && PostProcess.instance.isRenderingShadow)
            {
                Global3D.scene.context.setStencilReferenceValue(2);
            }
            else
            {
                Global3D.scene.context.setStencilReferenceValue(1);
            }
            super.draw(param1, param2);
            return;
        }// end function

        public static function CreatePixsMask(param1:int, param2:int, param3:int, param4:int, param5:String, param6:Boolean) : PixsMask
        {
            param5 = param5.replace(/\.jpg""\.jpg/i, ".abc");
            var _loc_7:* = FrObjectPool.getObject(PixsMask, "PixsMask");
            _loc_7.reinit(Global3D.scene.renderLayerList, param3, param4, param5, false, null, "-xy");
            _loc_7.setMateiralBlendMode(EBlendType.BLEND_ADDITIVE);
            _loc_7.material.materialParams.depthWrite = false;
            _loc_7.material.materialParams.colorKillvalue = 0;
            _loc_7.material.materialParams.depthCompare = Context3DCompareMode.ALWAYS;
            _loc_7.addedToScene(Global3D.scene);
            _loc_7.setLayer(Layer3DManager.PixsMaskLayer);
            _loc_7._mapX = param1 + param3 / 2;
            _loc_7._mapY = param2 + param4 / 2;
            _loc_7.rotationX = 40;
            _loc_7._isOverEffect = param6;
            return _loc_7;
        }// end function

    }
}
